home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Languguage OS 2
/
Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO
/
language
/
embedded
/
mcu332
/
332doc.arc
/
332BUGC4
< prev
next >
Wrap
Text File
|
1989-12-19
|
24KB
|
1,062 lines
DEBUG MONITOR USER'S MANUAL MOTOROLA
5-1 M68332BUG
DEBUG MONITOR USER'S MANUAL MOTOROLA
M68332BUG 5-1
CHAPTER 5
SYSTEM CALLS
5.1 INTRODUCTION
This chapter describes the 332Bug TRAP #15 handler, which allows system calls from user
programs. System calls access selected functional routines contained within 332Bug,
including input and output routines. TRAP #15 also transfers control back to 332Bug at the
end of a user program (refer to the .RETURN function, paragraph 5.2.14).
In the descriptions of some input and output functions, reference is made to the default input
port or the default output port. After power-up or reset, the default input and output port is port
0 (the M68332BCC terminal port).
5.1.1 Executing System Calls Through TRAP #15
To execute a system call from a user program simply insert a TRAP #15 instruction into the
source program. The code corresponding to the particular system routine is specified in the
word following the TRAP opcode, as shown in the following example.
Format in user program:
TRAP #15 System call to 332Bug
DC.W $xxxx Routine being requested (xxxx = code)
In some of the examples shown in the following descriptions, a SYSCALL macro is used with
the Motorola Macro Assembler (MASM) for MS-DOS/PC-DOS machines. This macro
automatically assembles the TRAP #15 call followed by the define constant for the function
code. The SYSCALL macro is:
SYSCALL MACRO
TRAP #15
DC.W \1
ENDM
Using the SYSCALL macro, the system call appears in the user program as:
SYSCALL <routine name>
It is necessary to create an equate file with the routine names equated to their respective
codes.
When using the 332Bug one-line assembler/disassembler, the SYSCALL macro and the
equates are pre-defined. Input: SYSCALL, space, function, carriage return.
EXAMPLE:
332Bug>M 3000;DI<CR>
0000 3000 00000000 ORI.B #$0,D0? SYSCALL .OUTLN <CR>
0000 3000 4E3F0022 SYSCALL .OUTLN
0000 3004 00000000 ORI.B #$0,D0? . <CR>
332Bug>
5.1.2 Input/Output String Formats
Within the context of the TRAP #15 handler are two string formats:
Pointer/Pointer Format: The string is defined by a pointer to the first character and a pointer
to the last character + 1.
Pointer/Count Format: The string is defined by a pointer to a count byte which contains the
count of the characters in the string followed by the string itself.
A line is defined as a string followed by a carriage return and a line feed.
5.2 SYSTEM CALL ROUTINES
Table 5-1 summarizes the TRAP #15 functions. Refer to the appropriate paragraph for a
description of the available system calls.
TABLE 5-1. 332Bug System Call Routines
CODE FUNCTION DESCRIPTION
$0000 .INCHR Input character
$0001 .INSTAT Input serial port status
$0002 .INLN Input line (pointer/pointer format)
$0003 .READSTR Input string (pointer/count format)
$0004 .READLN Input line (pointer/count format)
$0005 .CHKBRK Check for break
$0020 .OUTCHR Output character
$0021 .OUTSTR Output string (pointer/pointer format)
$0022 .OUTLN Output line (pointer/pointer format)
$0023 .WRITE Output string (pointer/count format)
$0024 .WRITELN Output line (pointer/count format)
$0025 .WRITDLN Output line with data (pointer/count format)
$0026 .PCRLF Output carriage return and line feed
$0027 .ERASLN Erase line
$0028 .WRITD Output string with data (pointer/count format)
$0029 .SNDBRK Send break
$0040 .TM_INI Timer initialization
$0041 .TM_STR0 Start timer at T=0
$0042 .TM_RD Read timer
$0043 .DELAY Timer delay function
$0063 .RETURN Return to 332Bug
$0064 .BINDEC Convert binary to Binary Coded Decimal (BCD)
$0067 .CHANGEV Parse value
$0068 .STRCMP Compare two strings (pointer/count format)
$0069 .MULU32 Multiply two 32-bit unsigned integers
$006A .DIVU32 Divide two 32-bit unsigned integers
.INCHR Input Character Routine .INCHR
5.2.1 Input Character Routine
SYSCALL .INCHR
TRAP CODE: $0000
Reads a character from the default input port. The character remains in the stack.
Entry Conditions:
SP ==> Space for character <byte>
Word fill <byte>
Exit Conditions:
SP ==> Character <byte>
Word fill <byte>
EXAMPLE:
SUBQ.L #2,SP Allocate space for result
SYSCALL .INCHR Call .INCHR
MOVE.B (SP)+,D0 Load character in D0
.INSTAT Input Serial Port Status .INSTAT
5.2.2 Input Serial Port Status
SYSCALL .INSTAT
TRAP CODE: $0001
Checks the default input port buffer for characters. The condition codes are set to indicate the
result of the operation.
Entry Conditions:
No arguments or stack allocation required
Exit Conditions:
Z (zero) = 1 if the receiver buffer is empty
EXAMPLE:
LOOP SYSCALL .INSTAT Any characters?
BEQ.S EMPTY No, branch
SUBQ.L #2,A7 Yes, then
SYSCALL .INCHR Read them
MOVE.B (SP)+,(A0)+ In buffer
BRA.S LOOP Check for more
EMPTY
.INLN Input Line Routine .INLN
5.2.3 Input Line Routine
SYSCALL .INLN
TRAP CODE: $0002
Reads a line from the default input port. The minimum buffer size is 256 bytes.
Entry Conditions:
SP ==> Address of string buffer <long>
Exit Conditions:
SP ==> Address of last character in the string+1 <long>
EXAMPLE:
If A0 contains the string destination address:
SUBQ.L #4,A7 Allocate space for result
PEA (A0) Push pointer to destination
TRAP #15 (May also invoke by SYSCALL
DC.W 2 macro (''SYSCALL .INLN'')
MOVE.L (A7)+,A1 Retrieve address of last character+1
NOTE
A line is a string of characters terminated by a carriage return (<CR>). The
maximum allowed size is 254 characters. The terminating <CR> is not included
in the string. See control character processing as described in paragraph 1.7,
Terminal Input/Output Control.
.READSTR Read String Into Variable-Length Buffer .READSTR
5.2.4 Read String Into Variable-Length Buffer
SYSCALL .READSTR
TRAP CODE: $0003
Reads a string of characters from the default input port into a buffer. The first byte in the buffer
defines the maximum number of characters that can be written to the buffer. The buffer's size
should be no less than the first byte + 2. The maximum number of characters written to a
buffer is 254 characters, making the maximum buffer size 256. On exit, the count byte
defines the number of characters in the buffer. Enter a carriage return (<CR>) and line feed
(<LF>) to terminate the input. The characters echo to the default output port. <CR> is not
echoed.
Entry Conditions:
SP ==> Address of input buffer <long>
Exit Conditions:
SP ==> Top of stack
The count byte containing the number of bytes in the buffer.
EXAMPLE:
If A0 contains the string buffer address;
PEA (A0) Push buffer address
TRAP #15 (May also invoke by SYSCALL
DC.W 3 macro (''SYSCALL .READSTR'')
NOTE
This routine allows the caller to define the maximum character input length (254
characters). If more than 254 characters are entered, then the buffer input is
truncated. See control character processing as described in paragraph 1.7
Terminal Input/Output Control.
.READLN Read Line to Fixed-Length Buffer .READLN
5.2.5 Read Line to Fixed-Length Buffer
SYSCALL .READLN
TRAP CODE: $0004
Reads a string of characters from the default input port. Characters echo to the default output
port. A string consists of a count byte followed by the characters read from the input. The
count byte indicates the number of characters read from the input as well as the number of
characters in the input string, excluding carriage return <CR> and line feed <LF>. A string
may be as many as 254 characters.
Entry Conditions:
SP ==> Address of input buffer <long>
Exit Conditions:
SP ==> Top of stack
The first byte in the buffer indicates the string length.
EXAMPLE:
If A0 points to a 256 byte buffer;
PEA (A0) Long buffer address
SYSCALL .READLN And read a line from the default input port
NOTE
The caller must allocate 256 bytes for a buffer. Input are limited to 254
characters. <CR> and <LF> are sent to default output following echo of the
input. See control character processing as described in paragraph 1.7,
Terminal Input/Output Control.
.CHKBRK Check for Break .CHKBRK
5.2.6 Check for Break
SYSCALL .CHKBRK
TRAP CODE: $0005
Returns zero (0) status in condition code register if break status is detected at the default
input port.
Entry Conditions:
No arguments or stack allocation required
Exit Conditions:
Z flag set in CCR if break detected
EXAMPLE:
SYSCALL .CHKBRK
BEQ BREAK
.OUTCHR Output Character Routine .OUTCHR
5.2.7 Output Character Routine
SYSCALL .OUTCHR
TRAP CODE: $0020
Outputs a character to the default output port.
Entry Conditions:
SP ==> Character <byte>
Word fill <byte> (Placed automatically by the MCU)
Exit Conditions:
SP ==> Top of stack
Character is sent to the default I/O port.
EXAMPLE:
MOVE.B D0,-(SP) Send character in D0
SYSCALL .OUTCHR To default output port
.OUTSTR Output String Using Pointers .OUTSTR
.OUTLN .OUTLN
5.2.8 Output String Using Pointers
SYSCALL .OUTSTR
TRAP CODE: $0021
SYSCALL .OUTLN
TRAP CODE: $0022
.OUTSTR outputs a string of characters to the default output port. .OUTLN outputs a string of
characters followed by a <CR><LF> sequence.
Entry Conditions:
SP ==> Address of first character <long>
+4 Address of last character + 1 <long>
Exit Conditions:
SP ==> Top of stack
EXAMPLE:
If A0 = start of string and A1 = end of string+1
MOVEM.L A0/A1,-(SP) Load pointers to string
SYSCALL .OUTSTR And print it
.WRITE Output String Using Character Count .WRITE
.WRITELN .WRITELN
5.2.9 Output String Using Character Count
SYSCALL .WRITE
TRAP CODE: $0023
SYSCALL .WRITELN
TRAP CODE: $0024
.WRITE and .WRITELN format character strings with a count byte and output the string to the
default output port. After formatting, the count byte is the first byte in the string. The user
passes the starting address of the string. .WRITELN appends a <CR><LF> to the end of the
string.
Entry Conditions:
Four bytes of parameters are positioned in the stack as follows:
SP ==> Address of first character.<long>
+4; Address of last character +1 <long>.
Exit Conditions:
SP ==> Top of stack
EXAMPLE:
MESSAGE1 DC.B 9, "MOTOROLA "
MESSAGE2 DC.B 8, "QUALITY!"
PEA MESSAGE1(PC) Push address of string
SYSCALL .WRITE Use TRAP #15 macro
PEA MESSAGE2(PC) Push address of other string
SYSCALL .WRITE Invoke function again
.WRITE Output String Using Character Count .WRITE
.WRITELN .WRITELN
. . . . . would print out the following message:
MOTOROLA QUALITY!
Using .WRITELN instead of .WRITE outputs the following message:
MOTOROLA
QUALITY!
NOTE
The string must be formatted such that the first byte (the byte pointed to by the
passed address) contains the byte count of the string.
.PCRLF Print <CR><LF> .PCRLF
5.2.10 Print <CR><LF>
SYSCALL .PCRLF
TRAP CODE: $0026
.PCRLF sends a carriage return (<CR>) and a line feed (<LF>) to the default output port.
Entry Conditions:
No arguments or stack allocation required.
Exit Conditions:
None
EXAMPLE:
SYSCALL .PCRLF Output <CR><LF>
.ERASLN Erase Line .ERASLN
5.2.11 Erase Line
SYSCALL .ERASLN
TRAP CODE: $0027
Use .ERASLN to erase the line at the present cursor position. If the terminal type flag is set
for hardcopy mode, a carriage return (<CR>) and line feed (<LF>) are issued instead.
Entry Conditions:
No arguments required.
Exit Conditions:
The cursor is positioned at the beginning of a blank line.
EXAMPLE:
SYSCALL .ERASLN
.WRITD Output String with Data .WRITD
.WRITDLN .WRITDLN
5.2.12 Output String with Data
SYSCALL .WRITD
TRAP CODE: $0028
SYSCALL .WRITDLN
TRAP CODE: $0025
These trap functions use the monitor I/O routine which outputs a user string containing
embedded variable fields. The user passes the starting address of the string and the data
stack address containing the data which is inserted into the string. The output goes to the
default output port.
Entry Conditions:
Eight bytes of parameter positioned in the stack as follow:
SP ==> Address of string <long>
Data list pointer <long>
A separate data stack or data list arranged as follows:
Data list pointer => Data for 1st variable in string <long>
Data for next variable <long>
Data for next variable <long>
Exit Conditions:
SP ==> Top of stack
.WRITD Output String with Data .WRITD
.WRITDLN .WRITDLN
EXAMPLE:
The following section of code .....
ERRMESSG DC.B $15,'ERROR CODE = ','|10,8Z|'
MOVE.L #3,-(A5) Push error code on data stack
PEA (A5) Push data stack location
PEA ERRMESSG(PC) Push address of string
SYSCALL .WRITDLN Invoke function
TST.L (A5)+ De-allocate data from data stack
. . . . . would print the message:
ERROR CODE = 3
NOTE
The string must be formatted such that the first byte (the byte pointed to by the
passed address) contains the byte count of the string, including the data field
specifiers.
Format data fields within the string as follows: '|<radix>,<fieldwidth>[Z]|' where
<radix> is the data's numerical base (in hexadecimal, i.e., ''A'' is base 10, ''10''
is base 16, etc.) and <fieldwidth> is the number of data characters to output.
The data is right-justified and left-most characters are truncated to size. Include
''Z'' to suppress leading zeros in the output.
All data is placed in the stack as longwords. Each time a data field is
encountered in the user string, a longword is displayed from the data stack.
The data stack is not destroyed by this routine. Use the call routine (see
example above) to de-allocate space in the data stack. If it is necessary for the
space in the data stack to be deallocated, it must be done using the call routine,
as shown in the above example.
.SNDBRK Send Break .SNDBRK
5.2.13 Send Break
SYSCALL .SNDBRK
TRAP CODE: $0029
Use .SNDBRK to send a break to the default output port.
Entry Conditions:
No arguments or stack allocation required
Exit Conditions:
The default port is sent ''break''.
EXAMPLE:
SYSCALL .SNDBRK
.TM_INI Timer Initialization .TM_INI
5.2.14 Timer Initialization
SYSCALL .TM_INI
TRAP CODE: $0040
Use .TM_INI to initialize the MC68332 MCU periodic interrupt timer. .TM_INI stops the timer
and then initializes it. .TM_INI does not restart the timer; use .TM_STR0 to restart the timer.
Timing is accomplished by counting the number of interrupt pulses generated. The default
interrupt pulse frequency is 125 milliseconds. Use this routine the first time the timer
functions are used.
Entry Conditions:
No arguments required.
Exit Conditions Different From Entry:
Periodic interrupt timer is stopped (no interrupts) and initialized for future
operation.
EXAMPLE:
SYSCALL .TM_INI Initialize timer
.TM_STR0 Start Timer at T=0 .TM_STR0
5.2.15 Start Timer at T=0
SYSCALL .TM_STR0
TRAP CODE: $0041
Use this routine to reset the timer to 0 and start it. The user can select values for the
MC68332 MCU periodic interrupt timer (periodic interrupt timing register (PICR) and periodic
interrupt control register (PITR)), or use the default values. The default values set the
interrupt frequency to 125 milliseconds and use level 6, vector 66. See Appendix C and
MC68332 Overview, paragraph 4.1.7 Periodic Interrupt Timer for more details.
Entry Conditions:
SP ==> Timer control value (for PICR) <word>
Timer period value (for PITR) <word>
Exit Conditions Different From Entry:
Parameters are removed from the stack, the timer is started, and the
interrupt pulse counter is cleared. If the user's interrupt level, as defined
in the status register (SR), disables the timer interrupts, the SR interrupt
mask bits are changed to allow timer interrupts.
If the value of PICR is not equal to the power-up default value, $000F, the
old vector number is restored to the default 332Bug value.
EXAMPLE 1:
SYSCALL .TM_STR0
EXAMPLE 2:
MOVE.L #0,-(A7) Reset the timer to zero and start it with the default
values.
SYSCALL .TM_STR0
.TM_STR0 Start Timer at T=0 .TM_STR0
EXAMPLE 3:
MOVE.L #$00000002,-(A7) Reset the timer to zero and start it with the default
control value (PICR) and a period value (PITR) of
$0002 (=244 usec/interrupt).
SYSCALL .TM_STR0
EXAMPLE 4:
MOVE.L #$054400A0,-(A7) Reset the timer to zero and start it with the control
value (PICR) of $0544 (level 5, vector 68 = $44)
and a period value (PITR) of $00A0 (=19.5
msec/interrupt).
SYSCALL .TM_STR0
.TM_RD Read Timer .TM_RD
5.2.16 Read Timer
SYSCALL .TM_RD
TRAP CODE: $0042
Use this routine to read the timer value (the timer value is the number of interrupt pulses
generated). Initialize (.TM_INI) and start (.TM_STR0) the timer before using the .TM_RD
function.
Entry Conditions:
SP ==> Space for result <long>
Exit Conditions Different From Entry:.
SP ==> Time (number of interrupt pulses) <long>. The timer keeps
running after the read.
EXAMPLE:
SUBQ.L #4,A7 Allocate space for result
SYSCALL .TM_RD Read timer
MOVE.L (SP)+,D0 Load interrupt pulse count
.DELAY Timer Delay Function .DELAY
5.2.17 Timer Delay Function
SYSCALL .DELAY
TRAP CODE: $0043
The .DELAY function generates timing delays based on the processor clock. This function
uses the MC68332 MCU periodic interrupt timer for operation. The user specifies the desired
delay count (number of interrupt pulses generated). .DELAY returns system control to the
user after the specified delay is completed. Initialize (.TM_INI) and start (.TM_STR0) the timer
before using the .TM_RD function.
Entry Conditions:
SP ==> Delay time (number of interrupt pulses) <long>
Exit Conditions Different From Entry:
SP ==> The timer keeps running after the delay and parameters are
removed from the stack.
EXAMPLE:
SYSCALL .TM INI Initialize timer
SYSCALL .TM_STR0 Start timer
PEA.L &1500 Load a 1500 interrupt pulse delay
SYSCALL .DELAY
*
*
*
PEA.L &50000 Load a 50000 interrupt pulse delay
SYSCALL .DELAY
.RETURN Return to 332Bug .RETURN
5.2.18 Return to 332Bug
SYSCALL .RETURN
TRAP CODE: $0063
.RETURN restores control to 332Bug from the target program. First, any breakpoints
inserted in target code are removed. Then the target state is saved in the register image
area. Finally, the routine returns to 332Bug.
Entry Conditions:
No arguments required.
Exit Conditions:
Control is returned to 332Bug.
EXAMPLE:
SYSCALL .RETURN Return to 332Bug
.BINDEC Calculate BCD Equivalent Specified Binary Number .BINDEC
5.2.19 Calculate BCD Equivalent Specified Binary Number
SYSCALL .BINDEC
TRAP CODE: $0064
This function takes a 32-bit unsigned binary number and changes it to its equivalent BCD
(Binary Coded Decimal Number).
Entry Conditions:
SP ==> Argument: Hex number <long>
Space for result <2 long>
Exit Conditions:
SP ==> Decimal number (2 Most Significant Digits) <long>
(8 Most Significant Digits) <long>
EXAMPLE:
SUBQ.L #8,A7 Allocate space for result
MOVE.L D0,-(SP) Load hex number
SYSCALL .BINDEC Call .BINDEC
MOVEM.L (SP)+,D1/D2 Load result
SYSCALL .REDIR Redirect I/O function
.CHANGEV Parse Value, Assign to Variable .CHANGEV
5.2.20 Parse Value, Assign to Variable
SYSCALL .CHANGEV
TRAP CODE: $0067
Parse a value in the user specified buffer. If the user specified buffer is empty, the user is
prompted for a new value, otherwise update the integer offset into the buffer to skip the value.
The new value is displayed and assigned to the variable unless the user's input is an empty
string.
Entry Conditions:
SP ==> Address of 32-bit offset into user's buffer
Address of user's buffer (pointer/count format string)
Address of 32-bit integer variable to change
Address of string to use in prompting and displaying value
Exit Conditions:
SP ==> Top of stack
EXAMPLE:
PROMPT DC.B $14,'COUNT = |10,8|'
GETCOUNT PEA PROMPT(PC) Point to prompt string
PEA COUNT Point to variable to change
PEA BUFFER Point to buffer
PEA POINT Point to offset into buffer
SYSCALL .CHANGEV Make the system call
RTS COUNT changed, return
.CHANGEV Parse Value, Assign to Variable .CHANGEV
If the above code was called with a syscall routine and BUFFER contained ''1 3'' in
pointer/count format and POINT contained 2 (longwords), then COUNT would be assigned
the value 3, and POINT would contain 4 (pointing to first character past 3). Note that POINT is
the offset of the buffer start address (not the address of the first character in the buffer) to the
next character to process. In this case, a value of 2 in POINT indicates that the space
between 1 and 3 is the next character to be processed. After calling .CHANGEV, the screen
would display the following line:
COUNT = 3
If the above code was called again, nothing could be parsed from BUFFER, so a prompt
would be issued. For example, if the string 5 is entered in response to the prompt.
COUNT = 3? 5<CR>
COUNT = 5
If in the previous example nothing had been entered at the prompt, COUNT would retain its
prior value.
COUNT = 3? <CR>
COUNT = 3
.STRCMP Compare Two Strings .STRCMP
5.2.21 Compare Two Strings
SYSCALL .STRCMP
TRAP CODE: $0068
An equality comparison is made and a boolean flag is returned to the caller. If the strings are
not identical the flag is $00, otherwise it is $FF.
Entry Conditions:
SP ==> Address of string#1
Address of string#2
Three bytes (unused)
Byte to receive string comparison result
Exit Conditions:
SP ==> Three bytes (unused)
Byte that received string comparison result
EXAMPLE:
If A1 and A2 contain the addresses of the two strings.
SUBQ.L #4,SP Allocate longword to receive result
PEA (A1) Push address of one string
PEA (A2) Push address of the other string
SYSCALL .STRCMP Compare the strings
MOVE.L (SP)+,D0 Pop boolean flag into data register
TST.B D0 Check boolean flag
BNE ARE SAME Branch if strings are identical
.MULU32 Unsigned 32 x 32 Bit Multiply .MULU32
5.2.22 Unsigned 32 x 32 Bit Multiply
SYSCALL .MULU32
TRAP CODE: $0069
Multiply two 32-bit unsigned integers and return the product on the stack as a 32-bit unsigned
integer. No overflow checking is performed.
Entry Conditions:
SP ==> 32-bit multiplier
32-bit multiplicand
32-bit space for result
Exit Conditions:
SP ==> 32-bit product (result from multiplication)
EXAMPLE:
Multiply D0 by D1, load result into D2.
SUBQ.L #4,SP Allocate space for result
MOVE.L D0,-(SP) Push multiplicand
MOVE.L D1,-(SP) Push multiplier
SYSCALL .MULU32 Multiply D0 by D1
MOVE.L (SP)+,D2 Get product
.DIVU32 Unsigned 32 x 32 Bit Divide .DIVU32
5.2.23 Unsigned 32 x 32 Bit Divide
SYSCALL .DIVU32
TRAP CODE: $006A
Divide two 32-bit unsigned integers and return the quotient on the stack as a 32-bit unsigned
integer. The case of division by zero is handled by returning the maximum unsigned value
$FFFFFFFF.
Entry Conditions:
SP ==> 32-bit divisor (value to divide by)
32-bit dividend (value to divide)
32-bit space for result
Exit Conditions:
SP ==> 32-bit quotient (result from division)
EXAMPLE:
Divide D0 by D1, load result into D2.
SUBQ.L #4,SP Allocate space for result
MOVE.L D0,-(SP) Push dividend
MOVE.L D1,-(SP) Push divisor
SYSCALL .DIVU32 Divide D0 by D1
MOVE.L (SP)+,D2 Get quotient